<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">
    <f:loadBundle basename="com.Bundle" var="msg"/>
    <h:body>
        <f:view>
            <h:form>
                <h1><h:outputText value="#{msg.items_datatable_header}"/></h1>
                <h:dataTable value="#{productBean.products}" var="item"
                             rowClasses="firstRow,secondRow"
                             columnClasses=""
                             headerClass="tableHeader"
                             style="border-collapse:collapse;vertical-align:middle; text-decoration:none;margin-left:15px;">
                    >
                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="#{msg.items_datatable_name}"/>
                        </f:facet>
                        <h:commandLink action="#{productBean.edit(item.id)}"> <h:outputText value="#{item.name}"/></h:commandLink>
                    </h:column>
                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="#{msg.items_datatable_code}"/>
                        </f:facet>
                        <h:outputText value="#{item.itemCode}"/>
                    </h:column>
                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="#{msg.items_datatable_sales_price}"/>
                        </f:facet>
                        <h:outputText value="#{item.sellingPrice}"/>
                    </h:column>

                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="#{msg.items_datatable_cost_price}"/>
                        </f:facet>
                        <h:outputText value="#{item.purchasingPrice}"/>
                    </h:column>

                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="#{msg.items_datatable_tax}"/>
                        </f:facet>
                        <h:outputText value="#{item.tax}"/>
                    </h:column>

                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="#{msg.items_datatable_remarks}"/>
                        </f:facet>
                        <h:outputText value="#{item.description}"/>
                    </h:column>
                    <f:facet name="footer">
                        <h:commandButton value="#{msg.new_button}" action="#{productBean.createNewProduct}"/>
                    </f:facet>
                </h:dataTable>
            </h:form>
            <h:panelGroup style=" visibility: #{productBean.editMode ? 'visible':'hidden'};">
                <h:form>
                    <h:inputHidden id="id" value="#{productBean.product.id}"/>
                    <h1><h:outputText value="#{msg.edit_header}"/></h1>
                    <h:panelGrid columns="2">

                        <h:outputLabel value="#{msg.product_category}" for="category" />
                        <h:selectOneMenu id="category" value="#{productBean.product.category}" title="Category" >
                            <f:selectItems value="#{productBean.categories}"/>
                        </h:selectOneMenu>

                        <h:outputLabel value="#{msg.product_name}" for="productName" />
                        <h:inputText id="productName" value="#{productBean.product.name}" title="ProductName"  required="true"/>

                        <h:outputLabel value="#{msg.product_item_code}" for="itemCode" />
                        <h:inputText id="itemCode" value="#{productBean.product.itemCode}" title="Item Code"  required="true"/>

                        <h:outputLabel value="#{msg.product_cost_price}" for="costPrice:" />
                        <h:inputText id="costPrice" value="#{productBean.product.purchasingPrice}" title="costPrice"  required="true"/>

                        <h:outputLabel value="#{msg.product_sales_price}" for="salesPrice" />
                        <h:inputText id="salesPrice" value="#{productBean.product.sellingPrice}" title="salesPrice"  required="true"/>

                        <h:outputLabel value="#{msg.items_datatable_tax}" for="tax" />
                        <h:inputText id="tax" value="#{productBean.product.tax}" title="Tax"  required="true"/>


                        <h:outputLabel value="#{msg.items_datatable_remarks}" for="remarks" />
                        <h:inputText id="remarks" value="#{productBean.product.description}" title="Remarks"  required="true"/>

                    </h:panelGrid>
                    <h:commandButton action="#{productBean.save}" value="#{msg.save_button}" />
                </h:form>

            </h:panelGroup>
        </f:view>

    </h:body>
</html>

